package com.project.ToDone;

import java.util.ArrayList;

/**
 * The holder class for all user's information for our program. 
 * 
 * @author Matthew Guzdial
 *
 */

public class User {
	private ToDoList toDoList;
	private String name, eMail, loginId, password;
	boolean newUser;
	
	public User(String name, String eMail, String loginId, String password){
		this.name=name;
		this.eMail=eMail;
		this.loginId=loginId;
		this.password=password;
		
		toDoList=new ToDoList();
		
		boolean newUser=true;
	}
	
	public String toString()
	{
		return loginId;
	}
	
	/**
	 * A method that checks a given username and password against a User's own
	 * 
	 * @param username
	 * @param password
	 * @return zero if all correct, 1 for incorrect username, 2 for incorrect password, 3 for all wrong
	 */
	public int validate(String username, String password){
		if(checkUsername(username)&&checkPassword(password))
		{
			return 0;
		}
		else if(checkUsername(username) && !checkPassword(password))
		{
			return 1;
		}
		else if(checkPassword(password) && !checkUsername(username))
		{
			return 2;
		}
		else
		{
			return 3;
		}
	}
	
	/**
	 * Checks a username against a user's own
	 * 
	 * @param username
	 * @return true if it matches, false otherwise
	 */
	public boolean checkUsername(String username){
		if(this.loginId.equals(username))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	/**
	 * Checks a password against a user's own
	 * 
	 * @param password
	 * @return true if it matches, false otherwise
	 */
	public boolean checkPassword(String password){
		if(this.password.equals(password))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	/**
	 * Adds an event e to user's to do list
	 * 
	 * @param e
	 */
	public void addEvent(Event e){
		toDoList.addEvent(e);
	}
	
	/**
	 * Getter for User's toDoList
	 * 
	 * @return User's toDoList
	 */
	public ToDoList getToDoList(){
		return toDoList;
	}
	
	/**
	 * Getter for User's name
	 * 
	 * @return User's name
	 */
	public String getName(){
		return name;
	}
	
	/**
	 * Getter for User's email
	 * 
	 * @return User's email
	 */
	public String getEMail(){
		return eMail;
	}
	
	/**
	 * Getter for User's username
	 * 
	 * @return User's username
	 */
	public String getUsername(){
		return loginId;
	}
	
	/**
	 * Getter for User's password
	 * 
	 * @return User's password
	 */
	public String getPassword(){
		return password;
	}
	
	/**
	 * If true, is new user, if oldUser return false
	 * 
	 * @return
	 */
	public boolean checkNewUser(){
		return newUser;
	}
	
	//Setters
	public void setToDoList(ToDoList toDo){
		toDoList=toDo;
	}
	
	/**
	 * Sets newUser to false, making it old
	 * 
	 */
	public void setOldUser(){
		newUser=false;
	}
	
	public String[] getToDoListStringArray()
	{
		return toDoList.toArrayOfStrings();
		
	}
	
	
	/**
	 * Get's the users events and returns them upwards
	 * 
	 * @return the events
	 */
	public ArrayList<Event> getToDoListEvents()
	{
		return toDoList.getEvents();
	}
	
	/**
	 * Filter events by completion
	 * 
	 * @return
	 */
	public ArrayList<Event> filterEventsComplete()
	{
		return toDoList.filterEventsByCompletion();
	}
	
	/**
	 * Filter events by incompletion
	 * @return
	 */
	public ArrayList<Event> filterEventsIncomplete()
	{
		return toDoList.filterEventsByIncompletion();
	}
	
	/**
	 * Filter events by Date
	 * @param date
	 * @return
	 */
	public ArrayList<Event> filterEventsDateAfter(String date)
	{
		return toDoList.filterEventsByDateAfter(date);
	}
	
	/**
	 * Gets the events after the specific date
	 * 
	 * @param date The date to work with
	 * @return
	 */
	public ArrayList<Event> filterEventsDateBefore(String date)
	{
		return toDoList.filterEventsByDateBefore(date);
	}
	
	/**
	 * Filter events by type
	 * @param string Type
	 * @return
	 */
	public ArrayList<Event> filterEventsType(String type)
	{
		return toDoList.filterEventsByType(type);
	}
	
	/**
	 * Gets event locations
	 */
	public ArrayList<String> getLocations(){
		return toDoList.getLocations();
	}
}
